package com.cnb.servlet.v2.beans.factory.support;

import com.cnb.servlet.v2.beans.config.BeanDefinition;
import com.cnb.servlet.v2.beans.factory.BeanFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DefaultListableBeanFactory implements BeanFactory {

    /**
     * 这里保存的是Bean的定义信息
     */
    public Map<String, BeanDefinition> beanDefinitionMap = new HashMap<String,BeanDefinition>();

    @Override
    public Object getBean(String beanName) {
        return null;
    }

    @Override
    public <T> T getBean(Class<T> requiredType) {
        return null;
    }

    /**
     * 注册Bean的定义信息
     * @param beanDefinitions
     */
    public void doRegistBeanDefinition(List<BeanDefinition> beanDefinitions) throws Exception {
        for (BeanDefinition beanDefinition : beanDefinitions) {
            String beanName = beanDefinition.getFactoryName();
            if(this.beanDefinitionMap.containsKey(beanName)){
                throw new Exception("[" + beanName + "]已经存在!");
            }
            this.beanDefinitionMap.put(beanName,beanDefinition);
        }
    }
}
